import 'package:flutter/material.dart';
import 'package:my_app/utils/index.dart';
import 'package:path_provider/path_provider.dart';

class ExampleLoggerAndWidgetsizePage extends StatefulWidget {
  const ExampleLoggerAndWidgetsizePage({super.key});

  @override
  State<ExampleLoggerAndWidgetsizePage> createState() => _ExampleLoggerAndWidgetsizePageState();
}

class _ExampleLoggerAndWidgetsizePageState extends State<ExampleLoggerAndWidgetsizePage> {

  final GlobalKey containerKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Flutter demo")),
      body: Column(
        children: [
          Container(
            padding: const EdgeInsets.all(12),
            child: Center(
              child: ElevatedButton(
                onPressed: () async {
                  LogUtil.v("verbose message");
                },
                child: const Text("verbose log"),
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(12),
            child: Center(
              child: ElevatedButton(
                onPressed: () async {
                  LogUtil.d("debug message");
                },
                child: const Text("debug log"),
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(12),
            child: Center(
              child: ElevatedButton(
                onPressed: () async {
                  LogUtil.i("info message");
                },
                child: const Text("info"),
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(12),
            child: Center(
              child: ElevatedButton(
                onPressed: () async {
                  LogUtil.w("warning message");
                },
                child: const Text("warning log"),
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(12),
            child: Center(
              child: ElevatedButton(
                onPressed: () async {
                  LogUtil.e("error message");
                },
                child: const Text("error log"),
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(12),
            child: Center(
              child: ElevatedButton(
                onPressed: () async {
                  LogUtil.wtf("wtf message");
                },
                child: const Text("wtf log"),
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.all(12),
            child: Center(
              child: ElevatedButton(
                onPressed: () {
                  getTemporaryDirectory().then((value) {
                    LogUtil.i(value);
                  });
                  getApplicationSupportDirectory().then((value) {
                    LogUtil.i(value);
                  });
                  getApplicationDocumentsDirectory().then((value) {
                    LogUtil.i(value);
                  });
                  getExternalStorageDirectory().then((value) {
                    LogUtil.i(value);
                  });
                },
                child: const Text("查看文件"),
              ),
            ),
          ),
          Container(
            key: containerKey,
            padding: const EdgeInsets.all(12),
            child: Center(
              child: ElevatedButton(
                onPressed: () {
                  LogUtil.d(
                    "BuildContext的方式:${context.findRenderObject()?.paintBounds.size}\n"
                    "GlobalKey的方式:${containerKey.currentContext?.findRenderObject()?.paintBounds.size}"
                  );
                },
                child: const Text("获取组件的尺寸"),
              ),
            ),
          ),
        ],
      )
    );
  }
}
